<route lang="json5" type="page">
{
  style: { navigationBarTitleText: '企微JSSDK', navigationBarBackgroundColor: '#fff' },
}
</route>

<template>
  <div class="mt-5 px-[12px] grid grid-cols-2 gap-2">
    <wd-button @click="handleScan">扫一扫</wd-button>
    <wd-button @click="handleChooseImage">选择图片</wd-button>
    <wd-button @click="handleOpenEnterpriseChat">打开会话</wd-button>
    <wd-button @click="handleSendChatMessage">分享消息到当前会话</wd-button>
    <wd-button @click="handleShareAppMessage">自定义转发到会话</wd-button>
    <wd-button @click="handleShareWechatMessage">自定义转发到微信</wd-button>
    <wd-button @click="handleShareToExternalContact">群发消息给客户</wd-button>
    <wd-button @click="goPage('/pages/job/summary')">goJobSummary</wd-button>
    <wd-button @click="goPage('/pages/intelligent/chathistory')">goChatHistory</wd-button>
  </div>
</template>

<script setup lang="ts">
import { reactive } from 'vue'
import * as ww from '@wecom/jssdk'
import { registerWeChat } from '@/utils/wecom'

registerWeChat()

const handleScan = () => {
  ww.scanQRCode({
    needResult: true,
    scanType: ['qrCode', 'barCode'],
    success(res: any) {
      console.log(res)
    },
    fail(res: any) {
      console.log(res)
    },
  })
}

const handleChooseImage = () => {
  ww.chooseImage({
    count: 1,
    sizeType: ['original', 'compressed'],
    sourceType: ['album', 'camera'],
    defaultCameraMode: 'batch',
    isSaveToAlbum: true,
    success: (res: any) => {
      console.log(res)
    },
    fail: (res: any) => {
      console.log(res)
    },
  })
}

const handleGetBluetoothAdapterState = () => {
  ww.getBluetoothAdapterState({
    success: (res: any) => {
      console.log('getBluetoothAdapterState', res)
    },
    fail: (res: any) => {
      console.log('getBluetoothAdapterState', res)
    },
  })
}

const handleOpenEnterpriseChat = () => {
  ww.openEnterpriseChat({
    groupName: '',
    userIds: ['ShiNingNing'],
    externalUserIds: ['wmbcG1BgAAlFcG8Nigyl8MbPYbd6nF6g'],
    success: (res: any) => {
      console.log('打开会话success', res)
      // ww.sendChatMessage({
      //   msgtype: "text",
      //   text: {
      //     content: "你好你好你好你好你好你好你好"
      //   }
      // });
    },
    fail: (res: any) => {
      console.log('打开会话fail', res)
    },
  })
}

const handleShareAppMessage = () => {
  ww.shareAppMessage({
    title: '企业微信',
    desc: '自定义转发到会话',
    link: 'https://work.weixin.qq.com/',
    imgUrl: 'https://res.mail.qq.com/node/ww/wwmng/style/images/index_share_logo$13c64306.png',
  })
}

const handleShareWechatMessage = () => {
  ww.shareWechatMessage({
    title: '企业微信',
    desc: '自定义转发到微信',
    link: 'https://work.weixin.qq.com/',
    imgUrl: 'https://res.mail.qq.com/node/ww/wwmng/style/images/index_share_logo$13c64306.png',
  })
}

const handleShareToExternalContact = () => {
  ww.shareToExternalContact({
    text: {
      content: '群发消息给客户',
    },
  })
}

const handleSendChatMessage = () => {
  ww.sendChatMessage({
    msgtype: 'text',
    text: {
      content: '你好，分享消息到当前会话',
    },
  })
}

function goPage(url: string) {
  uni.navigateTo({
    url,
  })
}
</script>
